//
// Created by jackzhous on 2019/7/23.
//

#ifndef OPENSL_OPENSL_DEMO_H
#define OPENSL_OPENSL_DEMO_H

#include <android/log.h>
#include <pthread.h>
#include <SLES/OpenSLES.h>
#include <SLES/OpenSLES_Android.h>

#define LOG(...) __android_log_print(ANDROID_LOG_DEBUG, "j_tag", __VA_ARGS__)

/**
 * 线程锁对象
 */
typedef struct {
    pthread_mutex_t* mutex;      //互斥量
    pthread_cond_t* condition;   //条件变量
    unsigned char value;        //锁标志
} LockUtil;

typedef struct {
    SLObjectItf engineObject;           //引擎始祖对象
    SLEngineItf engineInterface;        //引擎接口

    SLObjectItf recorderObject;
    SLRecordItf recorderInterface;

    SLObjectItf playerObject;
    SLPlayItf   playerInterface;

    SLObjectItf outputMixObject;

    SLAndroidSimpleBufferQueueItf  androidBufferQueueItf;     //数据缓冲队列

    SLDataLocator_AndroidSimpleBufferQueue queue;
    SLDataFormat_PCM pcmFormat;             //音频格式
    SLDataLocator_OutputMix outputMix;      //混音器数据描述
    SLDataLocator_IODevice ioDevice;        //io设备描述

    SLDataSource  source;           //音频数据来源的信息
    SLDataSink  sink;               //音频数据输出信息

    LockUtil lock;
} OpenSLHelper;


void lockInit(LockUtil *lock);
void lockWait(LockUtil *lock);
void lockNotify(LockUtil *lock);
void lockDestroy(LockUtil *lock);


void openSLInit(OpenSLHelper *slHelper);
void openSLDestroy(OpenSLHelper *slHelper);

void recorderInit(OpenSLHelper *slHelper, SLuint32 channels, SLuint32 sampleRate);
void playerInit(OpenSLHelper *slHelper, SLuint32 channels, SLuint32 sampleRate);
#endif //OPENSL_OPENSL_DEMO_H
